import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

/**
 * lambda 表达式
 */
public class Test {
	public static void main(String[] args) {
		List<String> list = new ArrayList<>();
		list.add("new world");
		list.add("hello");
		
		//1. 匿名内部类
		Collections.sort(list, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return Integer.compare(o1.length(), o2.length());
			}
		});
		System.out.println("匿名内部类排序:");
		list.forEach(System.out :: println);
		
		//2. 常规lambda
		Collections.sort(list, (s1, s2) -> s1.compareToIgnoreCase(s2));
		System.out.println("常规lambda排序:");
		list.forEach(System.out :: println);
		
		//3. lambda方法引用
		Collections.sort(list, String :: compareToIgnoreCase);
		System.out.println("lambda方法引用排序:");
		list.forEach(System.out :: println);
		
		//4. Comparator接口静态方法+方法引用
		Collections.sort(list, Comparator.comparing(String :: length));
		System.out.println("Comparator接口静态方法+方法引用排序:");
		list.forEach(System.out :: println);
		
		int[] a = new int[]{1, 2, 3, 4, 5};
		long x = Stream.of(a).count();
		int a1;
		int a2;
		int a3;
		int a4;
		int a5;
		long x2 = Stream.of(a1 = 1, a2 = 2, a3 = 3, a4 = 4, a5 = 5).count();
		System.out.println(x2);
		long y = Arrays.stream(a, 0, a.length).count();
		System.out.println(y);
		long y2 = Arrays.stream(a, 0, a.length).count();
		System.out.println(y2);
	}
}
